function Trim(s)
{
  // Remove leading spaces and carriage returns

  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function LoadExternalData (framename, script_name, parameter) {
    LRPC (framename, script_name+"?PageMode=RPC&"+parameter, 0);
}

function LoadRPC (framename, script_name, parameter) {
    LRPC (framename, script_name+"?PageMode=RPC&"+parameter, 0);
}

function PassValue (formnamedotcomponent, component_value) {
    js_str = formnamedotcomponent+'.value='+component_value;
    eval(js_str);
}

function LoadRPCData(file){
  var scriptTag = document.getElementById('loadScript');
  var head = document.getElementsByTagName('head').item(0)
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
    script.type = 'text/javascript';
    script.id = 'loadScript';
    head.appendChild(script)
}

function StrToNumber (str_val) {
     str_val = str_val.replace(new RegExp(",", "g"),'');
     val     = parseFloat(str_val);
     return val;
}

function OpenPDF (url) {
    javascript:void window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no');
}

function LRPC (framename, script_name, isDebug) {
     var isExist = document.getElementById(framename);
     window.status="Loading ...";
     if (isExist==null) {
         var rpc=document.createElement("iframe");
         rpc.setAttribute("id", framename);
         document.getElementsByTagName("body")[0].appendChild(rpc);
         if (isDebug==1) document.getElementById(framename).style.display = "block";
         else document.getElementById(framename).style.display = "none";
         rpc.setAttribute("src",script_name);
     } else {
         if (isDebug==1) document.getElementById(framename).style.display = "block";
         else document.getElementById(framename).style.display = "none";
         document.getElementById(framename).src = script_name;
     }
     window.status="";
}

// add by Chandra ( 25 may 2009 )

 function cistFormatMoney(num){
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + num + '.' + cents);
 }
